package remotedcsinstancemanager.server.domaines.impl;

import java.util.Vector;

import remotedcsinstancemanager.server.domaines.LocalDomaineManager;
import remotedcsinstancemanager.server.domaines.RemoteDomaineManagerOperations;
import remotedcsinstancemanager.server.interfaces.Suscriber;

public class RemoteDomaineManagerImpl implements RemoteDomaineManagerOperations{
	private Vector<LocalDomaineManager> locals;
	/**
	 * constructeur
	 */
	public RemoteDomaineManagerImpl() {
		locals = new Vector<LocalDomaineManager>();
	}
	
	@Override
	public Suscriber[] getTopicsSuscribers(String topicName, LocalDomaineManager sender) {
		Vector<Suscriber> localsSuscribers = new Vector<Suscriber>();
		for(int i = 0;i<locals.size();i++){
			if(!locals.get(i).equals(sender)){
				Suscriber[] suscribers = locals.get(i).getTopicsSuscribers(topicName, null);
				if(suscribers[0] != null)
					localsSuscribers.add(suscribers[0]);
			}
		}
		if(localsSuscribers.size() == 0)
			return new Suscriber[]{null};
		Suscriber[] suscribers = new Suscriber[localsSuscribers.size()];
		for(int i = 0;i<suscribers.length;i++)
			suscribers[i] = localsSuscribers.get(i);
		return suscribers;
	}

	@Override
	public boolean register(LocalDomaineManager domaine) {		
		return locals.add(domaine);
	}

}
